/*
 * 广州丰石科技有限公司拥有本软件版权2020并保留所有权利。
 * Copyright 2020, Guangzhou Rich Stone Data Technologies Company Limited,
 * All rights reserved.
 */
package demo.vo;

import com.richstonedt.rziomp.common.enums.ExceptionEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * <b><code>R</code></b>
 * <p/>
 * Description
 * <p/>
 * <b>Creation Time:</b> 2020/12/28 6:00 下午.
 *
 * @author wyfd
 * @since rziomp-be 1.0.0
 */
@Data
@ApiModel
public class R<T> implements Serializable {


    @ApiModelProperty("状态码")
    private Integer code;

    @ApiModelProperty("状态信息")
    private String message;

    @ApiModelProperty("请求结果")
    private T t;

    public R(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public R(ExceptionEnum exceptionEnum, T t) {
        this.code = exceptionEnum.getCode();
        this.message = exceptionEnum.getMessage();
        this.t = t;
    }

    public R(ExceptionEnum exceptionEnum) {
        this.code = exceptionEnum.getCode();
        this.message = exceptionEnum.getMessage();
    }

    public R(Integer code, String message, T t) {
        this.code = code;
        this.message = message;
        this.t = t;
    }

    public static <T> R<T> success(T t) {
        return new R<>(ExceptionEnum.SUCCESS, t);
    }

    public static <T> R<T> success(String msg) {
        return new R<>(ExceptionEnum.SUCCESS.getCode(), msg);
    }

    public static <T> R<T> success(Integer code, String message) {
        return new R<>(code, message);
    }

    public static <T> R<T> failed(Integer code, String message) {
        return new R(code, message);
    }

    public static <T> R<T> failed(String message) {
        return new R<>(ExceptionEnum.FAIL.getCode(), message);
    }

}
